package com.base.kotlin.mvp

import android.arch.lifecycle.LifecycleObserver
import android.os.Bundle
import android.view.View
import com.base.fragment.BaseDialogFragment

abstract class BaseMvpKDialogFragment<T : BasePresenter<*, *>> : BaseDialogFragment(), IView.DefaultView {

    protected var mPresenter: T? = null

    abstract fun bindViewToPresenter(): T?

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        mPresenter = bindViewToPresenter()
        mPresenter?.let {
            lifecycle.addObserver(it as LifecycleObserver)
        }
        super.onViewCreated(view, savedInstanceState)
    }

    override fun onDestroy() {
        super.onDestroy()
        mPresenter?.let {
            lifecycle.removeObserver(it as LifecycleObserver)
        }
    }

    override fun onDefaultSuccess(action: Int, data: Any?) {

    }
}